#include<cstdio>
int a[100001],l[100001],r[100001];
int n;
int max(int x,int y)
{
	return x>y?x:y;
}
int main()
{
	freopen("test.in","r",stdin);
	freopen("test.out","w",stdout);
	scanf("%d",&n);
	while(n!=0)
	{
	   for(int i =1; i<=n;i++)
		   scanf("%d",&a[i]);
	   r[n]=n;
	   for(int i = 1;i <= n;i++)r[i]=l[i]=i;
	   for(int i = 2; i<=n;i++)
		while(a[l[i]-1]>=a[i])
			l[i]=l[l[i]-1];
	   for(int i=n-1;i>=1;i--)
		   while(a[r[i]+1]>=a[i])
			   r[i] = r[r[i]+1];
	   int ans = 0;
	   for(int i =1;i<=n;i++)
		   ans = max(ans,(r[i]-l[i]+1)*a[i]);
	   printf("%d\n",ans);
	   scanf("%d",&n);
	}
	return 0;
}

